home *** CD-ROM | disk | FTP | other *** search
- % Comments in Emerald go from '%' to end of line
- % This little program creates two processes, which alternate printing
- % hi and ho. The monitor in 'innerObject' provides the mutual exclusion
- % and synchronization.
-
- const initialObject == object initialObject
- const limit == 10
- const newobj ==
- object innerObject
- export Hi, Ho
- monitor
- var printHiNext : Boolean <- true
- const c : Condition == Condition.create
-
- operation Hi
- if ! printHiNext then
- wait c
- end if
- stdout.PutString["hi\^J"]
- printHiNext <- false
- signal c
- end hi
-
- operation Ho
- if printHiNext then
- wait c
- end if
- stdout.PutString["ho\^J"]
- printHiNext <- true
- signal c
- end ho
- end monitor
-
- process
- var i : Integer
- i <- 0
- loop
- exit when i = limit
- self.ho
- i <- i + 1
- end loop
- stdout.PutString["Ho'er done.\^J"]
- stdout.close
- end process
- end innerObject
-
- process
- var i : Integer
- stdin.close
- i <- 0
- loop
- exit when i = limit
- newobj.hi
- i <- i + 1
- end loop
- stdout.PutString["Hi'er done.\^J"]
- end process
- end initialObject
-